package lpg;

class Node
{
    Node(int value)
    {
        this(value, null);
    }

    Node(int value, Node next)
    {
        this.value = value;
        this.next = next;
    }

    public boolean equals(Object obj)
    {
        if (obj == this)
            return true;
        if (!(obj instanceof Node))
            return false;

        Node p = this;
        Node q = (Node)obj;
        for (; p != null && q != null; p = p.next, q = q.next)
        {
            if (p.value != q.value)
                return false;
        }
        return p == q; // Both P and Q are NULL?
    }

    public int hashCode()
    {
        int result = 1;
        for (Node p = this; p != null; p = p.next)
            result = 31 * result + p.value;
        return result;
    }

    int value = Util.NIL;
    Node next = null;

}
